import axios from 'axios';

const { VITE_REQUEST_URL } = import.meta.env;

const service = axios.create({
  withCredentials: false, // 是否允许跨域
  timeout: 1000 * 60 * 3, // 超时时间
  baseURL: VITE_REQUEST_URL
});

// 请求拦截
service.interceptors.request.use(
  (config: any) => {
    return config;
  },
  (error: any) => {
    Promise.reject(error);
  }
);

// 响应拦截
service.interceptors.response.use(
  (response: any) => {
    if (response.data.code === 200) {
      return Promise.resolve(response.data);
    } else {
      return Promise.reject(response.data);
    }
  },
  (error: any) => {
    return Promise.reject(error);
  }
);

export default service;
